<template>
	<view class="newBody">
		
		<view class="from_Items" @tap="go_Details(1)">
			<text class="title">加工单号</text>
			<text class="textCont">{{ProcessingNumber?ProcessingNumber:'请选择加工单号'}}</text>
			<i class="iconfont icon-xiangyou" style="margin-left:50rpx;"></i>
		</view>

		<view class="from_Items" @tap="go_Details(2)">
			<text class="title">产品名称</text>
			<text class="textCont">{{ProductName?ProductName:'请选择产品名称'}}</text>
			<i class="iconfont icon-xiangyou" style="margin-left:50rpx;"></i>
		</view>


		<view class="from_Items" @tap="go_Details(3)">
			<text class="title">工序名称</text>
			<text class="textCont">{{ProcessName?ProcessName:'请选择工序名称'}}</text>
			<i class="iconfont icon-xiangyou" style="margin-left:50rpx;"></i>
		</view>



		<view class="from_Items">
			<text class="title">合格数量</text>
			<input class="Input" placeholder="请输入合格数量" type="number" v-model="hgNumber" />
		</view>

		<view class="from_Items">
			<text class="title">返工数量</text>
			<input class="Input" placeholder="请输入返工数量" type="number" v-model="fgNumber" />
		</view>

		<view class="from_Items">
			<text class="title">废品数量</text>
			<input class="Input" placeholder="请输入废品数量" type="number" v-model="fpNumber" />
		</view>



		<view hover-class="jsShow" class="jsBtns" @tap="addCartChange">提交新增</view>




	</view>
</template>

<script>
	export default {
		data() {
			return {
				timeout: null,
				ProcessingNumber: '',
				ProductName: '',
				ProcessName: '',
				hgNumber: '',
				fgNumber: '',
				fpNumber: '',
			}
		},

		onShow() {
			uni.$on('otherFun', (res) => {
				//加工单号
				if (res.index == 1) {
					this.ProcessingNumber = res.ProcessingNumber;
				}
			});
		},

		methods: {

			addCartChange() {
				if (!this.ProcessingNumber) {
					this.debounce('请选择加工单号');
					return;
				}
				if (!this.ProductName) {
					this.debounce('请选择产品名称');
						return;
				}
				if (!this.ProcessName) {
					this.debounce('请选择工序名称');
						return;
				}
				if (!this.hgNumber) {
					this.debounce('请填写合格数量');
						return;
				}
				if (!this.fgNumber) {
					this.debounce('请填写返工数量');
						return;
				}
				if (!this.fpNumber) {
					this.debounce('请填写废品数量');
						return;
				}
			},

			debounce(str) {
				if (this.timeout) clearTimeout(this.timeout);
				this.timeout = setTimeout(() => {
					uni.showToast({
						icon: 'none',
						title: str
					});
					this.timeout = null;
				}, 500);
			},




			go_Details(index) {
				if (!this.ProcessingNumber && index == 2) {
					this.debounce('请先选择加工单号');
					return;
				};
				if (index == 3) {
					if (!this.ProcessingNumber && !this.ProductName) {
						this.debounce('请先选择加工单号');
						return;
					} else if (this.ProcessingNumber && !this.ProductName) {
						this.debounce('请先选择产品名称');
						return;
					}
				}
				uni.navigateTo({
					url: `new-addCar?index=${index}`
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.newBody {
		width: 750rpx;
		height: 100%;
		background-color: white;
	}

	.from_Items {
		width: 700rpx;
		height: 100rpx;
		margin: 0 auto;
		display: flex;
		flex-direction: row;
		align-items: center;
		border-bottom: 1rpx dashed #808080;

		.title {
			font-size: 30rpx;
		}

		.textCont {
			font-size: 30rpx;
			width: 450rpx;
			text-align: center;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			margin-left: 30rpx;
		}

		.Input {
			margin-left: 30rpx;
			width: 450rpx;
			height: 100rpx;
			text-align: center;

		}
	}

	.jsBtns {
		width: 600rpx;
		height: 80rpx;
		border-radius: 15rpx;
		color: white;
		background-color: #007AFF;
		text-align: center;
		line-height: 80rpx;
		letter-spacing: 10rpx;
		font-size: 40rpx;
		margin: 100rpx auto 0;
	}

	.jsShow {
		background-color: #131eff;
	}
</style>
